package collection;

import java.util.*;

public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:" + list);
        String e = list.get(1);
        System.out.println(e);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        e = list.set(2, "six");
        System.out.println(list);
        System.out.println("被替换的元素:" + e);
        Collections.reverse(list);
        for (int i = 0; i < list.size() / 2; i++) {
            String str = list.get(i);
            str = list.set(list.size() - 1 - i, str);
            list.set(i, str);
        }
        for (int i = 0; i < list.size() / 2; i++) {
            list.set(i, list.set(list.size() - 1 - i, list.get(i)));
        }
        System.out.println(list);
    }
}
